package cn.signalpha.modules.shop.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.shop.entity.OrderLogisticsDetail;
import cn.signalpha.modules.shop.mapper.OrderLogisticsDetailMapper;
import cn.signalpha.modules.shop.vo.OrderLogisticsDetailVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class OrderLogisticsDetailService extends ServiceImpl<OrderLogisticsDetailMapper, OrderLogisticsDetail> {

	/**
	 * 自定义分页
	 */
    public IPage<OrderLogisticsDetailVO> selectOrderLogisticsDetailPage(IPage<OrderLogisticsDetailVO> page, Map<String, Object> params) {
        return page.setRecords(baseMapper.selectOrderLogisticsDetailPage(page, params));
    }

	/**
	 * 自定义列表
	 */
	public List<OrderLogisticsDetailVO> selectOrderLogisticsDetailList(Map<String, Object> params) {
		return baseMapper.selectOrderLogisticsDetailPage(null, params);
	}

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<OrderLogisticsDetail> selectOrderLogisticsDetailWrapper(Map<String, Object> params) {
        QueryWrapper<OrderLogisticsDetail> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("id")), OrderLogisticsDetail::getId, params.get("id"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("orderNo")), OrderLogisticsDetail::getOrderNo, params.get("orderNo"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("logisticsId")), OrderLogisticsDetail::getLogisticsId, params.get("logisticsId"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("goodsId")), OrderLogisticsDetail::getGoodsId, params.get("goodsId"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("goodsNum")), OrderLogisticsDetail::getGoodsNum, params.get("goodsNum"));
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("goodsDetail")), OrderLogisticsDetail::getGoodsDetail, params.get("goodsDetail"));
        wrapper.lambda().orderByDesc(OrderLogisticsDetail::getId);
        return wrapper;
    }

	/**
	 * 订单号删除
	 */
	public void removeByOrderNo(String orderNo) {
		baseMapper.delete(Wrappers.<OrderLogisticsDetail>lambdaQuery().eq(OrderLogisticsDetail::getOrderNo, orderNo));
	}

}

